<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=utf-8" errorPage="/error.jsp" isELIgnored="false" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-tiles" prefix="tiles" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://www.opensymphony.com/oscache" prefix="cache" %>
<%@ taglib uri="http://atleap.blandware.com/taglib" prefix="atleap" %>
<html:xhtml />


<atleap:constants className="com.blandware.atleap.common.Constants" var="RESOURCE_TYPE_IMAGE" scope="page" />

<atleap:content identifier="information" ignore="true" />
<atleap:messages />

<c:set var="colNumber" value="2" />

<c:set var="imagesNumber" value="0" />
<c:set var="imagesInRow" value="0" />
<script type="text/javascript">
    function setGalleryImg(src, descr) {
        var img = document.getElementById("galleryImg");
        var description = document.getElementById("galleryDescr");
        var gallery = document.getElementById("galleryDiv");
        img.src = src;
        img.alt = descr;
        description.innerHTML = descr;
        gallery.style.visibility = "visible";
        return false;
    }
</script>
<div id="galleryDiv" style="visibility: hidden">
    <img id="galleryImg" src="" alt="" />
    <div id="galleryDescr"></div>
</div>
<table>
    <atleap:rewriteUrl var="createUrl" action="core/contentResource/callCreate">
        <atleap:param name="folder" value="/slideshow/" />
        <atleap:param name="type" value="${pageScope.RESOURCE_TYPE_IMAGE}" />
    </atleap:rewriteUrl>
    <atleap:resourceIterator var="resource" uriPrefix="/rw/resource/slideshow/" orderBy="r.uri" createUri="${createUrl}">
        <c:if test="${imagesInRow == 0}">
            <tr>
        </c:if>
        <c:set var="imagesNumber" value="${imagesNumber + 1}" />
        <atleap:rewriteUrl href="${resource.uri}" var="src" />
        <atleap:fieldValue valueMap="${resource.description}" var="description" filter="true" />
        <atleap:rewriteUrl var="editUrl" action="core/contentResource/callUpdate">
            <atleap:param name="id" value="${resource.id}"/>
        </atleap:rewriteUrl>
        <atleap:rewriteUrl var="deleteUrl" action="core/contentResource/delete">
            <atleap:param name="id" value="${resource.id}"/>
        </atleap:rewriteUrl>
        <td>
            <atleap:editCollection editUri="${editUrl}" createUri="${createUrl}" deleteUri="${deleteUrl}">
                <div class="galleryImgWrapper">
                    <a href="#" title="${description}" onclick="return setGalleryImg(&#039;${src}&#039;, &#039;${description}&#039;)">
                        <img src="${ctxPath}/servlet/thumbnail/?contentResourceId=${resource.id}" alt="${description}" border="0" />
                    </a>
                </div>
            </atleap:editCollection>
        </td>
        <c:set var="imagesInRow" value="${imagesInRow + 1}" />
        <c:if test="${imagesInRow == colNumber}">
            <c:set var="imagesInRow" value="0" />
            </tr>
        </c:if>
    </atleap:resourceIterator>
</table>
